package us.mmapp.util;

import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import us.mmapp.R;
import us.mmapp.entities.ObjectEntity;
import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ObjectEntityAdapter extends ArrayAdapter<ObjectEntity> {

    private ArrayList<ObjectEntity> items;

    public ObjectEntityAdapter(Context context, int textViewResourceId, ArrayList<ObjectEntity> items) {
            super(context, textViewResourceId, items);
            this.items = items;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.search_listview, null);
            }
            ObjectEntity o = items.get(position);
            if (o != null) {
            	ImageView img = (ImageView) v.findViewById(R.id.search_listview_icon);

        		if (o.getType() == 0)
    				img.setImageDrawable(getContext().getResources().getDrawable(R.drawable.photo_ballon));
    			if (o.getType() == 1)
    				img.setImageDrawable(getContext().getResources().getDrawable(R.drawable.video_ballon));
    			if (o.getType() == 2)
    				img.setImageDrawable(getContext().getResources().getDrawable(R.drawable.audio_ballon));
    			
                TextView tt = (TextView) v.findViewById(R.id.search_listview_title);
                TextView bt = (TextView) v.findViewById(R.id.search_listview_description);
                if (tt != null) {
                      tt.setText("Title: "+o.getTitle());                            
                      }
                if(bt != null){
                      bt.setText(o.getDescription());
                	}
            }
            return v;
    }
}